package aiingames.simulation.network;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.matsim.core.utils.collections.QuadTree;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;

public class Network {
	
	
	private QuadTree<Node> nodeQuad;
	private List<Link> links = new ArrayList<Link>();

	public Network(Envelope e) {
		this.nodeQuad = new QuadTree<Node>(e.getMinX(),e.getMinY(), e.getMaxX(), e.getMaxY());
	}
	
	public void createNode(Coordinate coord) {
		Node n = new Node(coord);
		this.nodeQuad.put(coord.x, coord.y, n);
	}
	
	public void createLink(Node from, Node to) {
		Link l = new Link(from, to);
		from.addOutLink(l);
		to.addInLink(l);
		this.links.add(l);
	}
	
	public Node getNearestNode(Coordinate coord) {
		return this.nodeQuad.get(coord.x, coord.y);
	}
	
	public List<Link> getLinks() {
		return this.links;
	}
	
	public Collection<Node> getNodes() {
		return this.nodeQuad.values();
	}

}
